
//

#import "ZWNavigationController.h"
#import "ZWTabBarController.h"
#import "ZWTabBar.h"
@interface ZWTabBarController ()

//@property(nonatomic,strong)ZWTabBar *tabbar;

@end

@implementation ZWTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    ZWTabBar *tabbar = [[ZWTabBar alloc]init];
    tabbar.clickBtn = ^{
        NSLog(@"控制器中点击了按钮");
    };
    // 初始化
    [self setValue:tabbar forKey:@"tabBar"];
    // Do any additional setup after loading the view.
    //  创建可变数组
    [self loadViewControllerWithClassName:@"ZWHomeTableViewController" WithTitleName:@"首页" WithImage:@"home"];
    [self loadViewControllerWithClassName:@"ZWMessageTableViewController" WithTitleName:@"消息" WithImage:@"message"];
    [self loadViewControllerWithClassName:@"ZWDiscoverViewController" WithTitleName:@"发现" WithImage:@"discover"];
    [self loadViewControllerWithClassName:@"ZWMeTableViewController" WithTitleName:@"我" WithImage:@"profile"];
}
// 创建一个对象方法加载控制器
- (UIViewController *)loadViewControllerWithClassName:(NSString *)ClassName WithTitleName:(NSString *)titleName WithImage:(NSString *)image {
    // 创建控制器
    UIViewController *vc = [[NSClassFromString(ClassName) alloc] init];
    // 设置title
    vc.title = titleName;
    // 设置原生态正常图片
    NSString *imageName1 = [NSString stringWithFormat:@"tabbar_%@", image];
    vc.tabBarItem.image = [[UIImage imageNamed:imageName1] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置原生态选中图片
    NSString *imageName2 = [NSString stringWithFormat:@"tabbar_%@_selected", image];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageName2] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置跟控制器
    ZWNavigationController *nav = [[ZWNavigationController alloc] initWithRootViewController:vc];
    // 添加到
    [self addChildViewController:nav];
    return nav;
}

@end
